package com.djhu.freepartner.web.service.impl;

import com.djhu.freepartner.bean.FavouritePost;
import com.djhu.freepartner.bean.PartnerPost;
import com.djhu.freepartner.service.IFavouritePostService;
import com.djhu.freepartner.service.IPartnerPostService;
import com.djhu.freepartner.utils.DateUtils;
import com.djhu.freepartner.web.control.model.FavouriteModel;
import com.djhu.freepartner.web.service.IFavouriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FavouriteServiceImpl implements IFavouriteService {

    @Autowired
    private IFavouritePostService favouritePostService;


    @Autowired
    private IPartnerPostService partnerPostService;

    @Override
    public boolean watch(FavouriteModel favouriteModel) {
        String postId = favouriteModel.getPostid();
        String userId = favouriteModel.getUserid();
        FavouritePost favouritePost = new FavouritePost();
        favouritePost.setCreateDate(DateUtils.now());
        favouritePost.setUserid(userId);
        favouritePost.setPostid(postId);

        PartnerPost post = partnerPostService.selectById(postId);
        favouritePost.setPostUserId(post.getCreateUserId());
        favouritePost.setPostUserName(post.getCreateUserusername());
        return favouritePostService.insert(favouritePost);
    }

    @Override
    public boolean unwatch(FavouriteModel favouriteModel) {
        String id = favouriteModel.getId();
        return favouritePostService.deleteById(id);
    }

    @Override
    public boolean list(FavouriteModel favouriteModel) {
        return false;
    }
}
